package com.bdqn.tour.servlet.Yml;

import com.alibaba.fastjson.JSONObject;
import com.bdqn.tour.pojo.City;
import com.bdqn.tour.service.CityService;
import com.bdqn.tour.service.impl.CityServiceimpl;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/ShowAll")
public class ShowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码
       req.setCharacterEncoding("UTF-8");
       resp.setCharacterEncoding("UTF-8");
       resp.setContentType("application/json");
       String text=req.getParameter("text");
       CityService cityService = new CityServiceimpl();
        List<City> getshow = cityService.Getshow(text);

//        req.getSession().setAttribute("getshow",getshow);
//        req.getRequestDispatcher("jd-index.jsp").forward(req,resp);
        //转为json格式
        String json = JSONObject.toJSONString(getshow);
        //输出
        PrintWriter out = resp.getWriter();
        out.print(json);
        //关闭
        out.close();

    }
}

